/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2014年12月29日         luwei
 */

package com.coocaa.launcher.sidebar.setting.item.common;

import android.content.Context;
import android.os.RemoteException;
import android.view.KeyEvent;
import android.view.View;

import com.coocaa.launcher.EasyLauncherActivity;
import com.coocaa.launcher.framework.sidebar.item.Item;
import com.coocaa.launcher.framework.sidebar.item.ItemFactory.ITEM;
import com.coocaa.launcher.framework.sidebar.item.ItemView;
import com.coocaa.launcher.sidebar.SettingData;
import com.coocaa.x.framework.utils.AsyncTask;
import com.coocaa.x.service.litecontent.LiteContentServiceConnecter;
import com.tianci.appstore.utils.SkyConstants;

public class Common extends Item {
    private SettingData mSettingData = null;

    public Common(Context context) {
        super(context);
    }

    @Override
    public void onItemFocusChange(View v, boolean focus) {
        // TODO Auto-generated method stub
        super.onItemFocusChange(v, focus);
    }

    @Override
    public boolean onItemKeyEvent(View v, int keycode, KeyEvent keyEvent) {
        return false;
    }

    @Override
    public void onItemClick(View v) {
        AsyncTask.runOnThread(new Runnable() {
            @Override
            public void run() {
                try {
                    if (mContext instanceof EasyLauncherActivity
                            && mSettingData.uri.equals("system://com.tianci.setting/tianci_setting")) {
                        ((EasyLauncherActivity) mContext).isSystemSetting = true;
                    }
                    LiteContentServiceConnecter.getService().call(mSettingData.uri);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        });
        super.onItemClick(v);
    }

    @Override
    public ItemView createItemView() {
        // TODO Auto-generated method stub
        return new CommonItem(mContext);
    }

    @Override
    public void setData(Object object) {
        this.mSettingData = (SettingData) object;
        mType = ITEM.valueOf(mSettingData.titleId);
        ((CommonItem) mItemView).updateIcon(SkyConstants.getIconId(mSettingData.iconId));
        ((CommonItem) mItemView).updateName(SkyConstants.getStringId(mSettingData.titleId));
    }
}
